package cn.sdormitory.controller.report;

import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.report.req.MorningExercisesStaReq;
import cn.sdormitory.report.service.MorningExercisesStaService;
import cn.sdormitory.report.vo.MorningExercisesStaVO;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author : yy
 * @date: 2025/4/12 8:28
 * @description: 早操统计
 */
@RestController
@Api(tags = "早操统计")
@RequestMapping("/report/morningExercises")
public class MorningExercisesStaController {
    @Resource
    private MorningExercisesStaService morningExercisesStaService;

    @ApiOperation("查询早操统计列表")
    @PostMapping(value = "/list")
    public CommonResult<CommonPage<MorningExercisesStaVO>> list(@RequestBody MorningExercisesStaReq exercisesStaReq) {
        IPage<MorningExercisesStaVO> page = morningExercisesStaService.list(exercisesStaReq);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation("导出早操统计列表")
    @PostMapping(value = "/export")
    public CommonResult export(HttpServletResponse response, @RequestBody MorningExercisesStaReq exercisesStaReq) {
        List<MorningExercisesStaVO> morningExercisesStaVOS = morningExercisesStaService.export(exercisesStaReq);
        try {
            EasyExcel.write(response.getOutputStream(), MorningExercisesStaVO.class).sheet("早操统计").doWrite(morningExercisesStaVOS);
            return CommonResult.success();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return CommonResult.failed();

    }


}
